import React, { useState } from 'react'
import PubSub from 'pubsub-js'

export default function Gege() {
    const [car, setCar] = useState('奥拓')
    const changeCarHandle=()=>{
        setCar('奥迪RS7')
        // 当换车以后发布数据,第一个参数类似于标示,订阅方的标示必须跟发布方的标示一致
        PubSub.publish('qiche', '奥迪RS7') 
    }
    return (
        <div>
            <h1>我是哥哥,我开{car}</h1>
            <button onClick={changeCarHandle}>换车</button>
        </div>
    )
}
